package com.xdwanj.action

import java.sql.DriverManager
import java.util.*

fun main(args: Array<String>) {
//    val url = "jdbc:sqlite::resource:scott.db"
    val url = "jdbc:sqlite:D:\\Project\\Java\\JavaProject\\SqliteStudy\\src\\main\\resources\\crime-database"
    var crime: Crime?
    var createTableSql = "create table if not exists crime\n" +
            "(\n" +
            "    id       text primary key,\n" +
            "    title    text,\n" +
            "    date     integer,\n" +
            "    is_soled integer\n" +
            ");"


//    var insertSql = "insert into crime(id, title, date, is_soled) values ();"
//    var emp: Emp? = null
//    var empList = mutableListOf<Emp>()
    val connection = DriverManager.getConnection(url)

    val statement = connection.createStatement()

    statement.execute(createTableSql)


    for (i in 1..100) {
//        crime = Crime(UUID.randomUUID(), "${i}crime", Date(), (i % 2) == 0)
        val insertSql =
            "insert into crime(id, title, date, is_soled) values ('${UUID.randomUUID()}', '${i}crime', '${Date()}', '${if (i % 2 == 0) 1 else 0}');"
        statement.execute(insertSql)
    }

//    while (rs.next()) {
//        emp = Emp(
//            empNo = rs.getInt("empNo"),
//            eName = rs.getString("eName"),
//            job = rs.getString("job"),
//            mgr = rs.getInt("mgr"),
//            hireDate = rs.getString("hireDate"),
//            sal = rs.getInt("sal"),
//            comm = rs.getString("comm"),
//            deptNo = rs.getInt("deptNo")
//        )
//        empList += emp
//        emp = null
//    }
//
//    rs.close()
//    statement.close()
//    connection.close()
//
//    empList.forEach {
//        println("it = $it")
//    }
}

data class Crime(
    var id: UUID,
    var title: String,
    var date: Date,
    var isSoled: Boolean
)
